using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using Microsoft.Phone.Tasks;
using Microsoft.Xna.Framework.Graphics;

namespace _15_puzzle_camera_wp8
{

    public class CameraManager
    {
        public event EventHandler<PhotoResult> CaptureEvent;
        public event EventHandler CaptureAborted;

        public void Capture()
        {
            var cameraCaptureTask = new CameraCaptureTask();
            cameraCaptureTask.Completed += cameraCaptureTask_Completed;
            cameraCaptureTask.Show();
        }

        private void cameraCaptureTask_Completed(object sender, PhotoResult e)
        {
            if (e.TaskResult == TaskResult.OK)
            {
                Debug.WriteLine("Capured! " + e.ChosenPhoto.Length.ToString());

                if (CaptureEvent != null)
                    CaptureEvent(this, e);
            }
            else if(e.TaskResult == TaskResult.Cancel)
            {
                Debug.WriteLine("The user aborted the CaptureTask :(");
                if (CaptureAborted != null)
                    CaptureAborted(this, e);
            }
            else
            {
                Debug.WriteLine("Something went wrong while capturing :(");
                if (CaptureAborted != null)
                    CaptureAborted(this, e);
            }

            
        }
    }
}
